/*
 * Copyright (C) 2019-2020 Alibaba Group Holding Limited
 */
#include <string.h>

#include <aos/cli.h>
#include <aos/kernel.h>
#include <aos/log.h>

#define HELP_INFO \
    "Usage:\n\tset level: log level 0~5\n" \
    "\t\t0:disable 1:F 2:E 3:W 4:I 5:D\n" \
    "\tadd ignore tag: log ignore tag\n" \
    "\tclear ignore tag: log ignore\n"

static void cmd_log_ctrl_func(char *wbuf, int wbuf_len, int argc, char **argv)
{
    int fmt_err = 1;
    if (argc >= 2) {
        if (0 == strcmp(argv[1], "level")) {
            if (argc == 3) {
                int level = atoi(argv[2]);
                if (level >=AOS_LL_NONE && level < LOG_MAX ) {
                    aos_set_log_level(level);
                    fmt_err = 0;
                }
            }
        } else if (0 == strcmp(argv[1], "ignore")) {
            if (argc == 3) {
                char *tag = argv[2];
                aos_add_log_tag_ignore(tag);
            } else {
                aos_add_log_tag_ignore(NULL);
            }
            fmt_err = 0;
        } 
    }

    if (fmt_err) {
        printf(HELP_INFO);
    }
}

void cli_reg_cmd_log(void)
{
    static const struct cli_command cmd_info = {
        "log",
        "log contrtol",
        cmd_log_ctrl_func,
    };

    aos_cli_register_command(&cmd_info);
}
